<!doctype html>
<html>
<head>
	<meta charset="UTF-8">
	<title>Document</title>
   	<link rel="stylesheet" href="../css/reset.css">
   	<link rel="stylesheet" href="../css/public.css">
   	<script src="../js/angular.min.js"></script>
</head>
<body>
<div class="login" ng-app="myApp" >
<header>
	<div class="con">
		<div class="logo"></div>
		<div class="tit">控制平台<var>.</var><span>登录界面</span></div>
	</div>
</header>

<div class="form_box">
	<h2>登录</h2>
	  <form name='form' novalidate ng-controller="form">
		
		<!-- 邮箱及验证开始 -->
	    <label for="email" style="margin-top: 20px;">你的邮箱：</label>
	    <input type="email" ng-focus="emailBool(false)" ng-blur="emailBool(true)" name="email" ng-model="email" id="email" required>
	    <div class="errorBox">
		    <span style="color:red;font-size:12px;" ng-show="emailBlur && form.email.$dirty && form.email.$invalid">
		    	<span ng-show="form.email.$error.required">请填写你的邮箱</span>
		    	<span ng-show="form.email.$error.email">你的邮箱格式有误</span>
		    </span>
	    </div>
	    <!-- 邮箱及验证结束 -->
		
		<!-- 密码及验证开始 -->
		<label for="userpassword">你的密码：</label>
	    <input type="password" ng-focus="passwordBool(false)" ng-blur="passwordBool(true)" name="password" ng-model="password" id="userpassword" required>
	   	<label for="savepassword">
	   		<input type="checkbox" id="savepassword" ng-model="savePassword">是否保存密码到该电脑上
	   	</label>
	    <div class="errorBox">
		    <span style="color:red;font-size:12px;" ng-show="passwordBlur && form.password.$dirty && form.password.$invalid">
		    	<span ng-show="form.password.$error.required">请填写你的密码</span>
		    	<span ng-show="form.password.$error.required">账号和密码有误</span>
		    </span>
	    </div>
	    <!-- 密码及验证结束 -->


	    <button ng-click="reset()">登录到控制平台</button>

	  </form>
</div>

<footer>
	<p>@2014 厦门尊尚时计贸易有限公司 zstime.com 闽ICP备14013630号 </p>
</footer>
</div>
<script>
	var app = angular.module('myApp', []);
	app.controller('form', function($scope) {
		// 获取本地存储的密码
		$scope.savePassword = true;
		$scope.userSign = JSON.parse(localStorage.getItem('userSign'));
		console.log($scope.userSign);
		if($scope.userSign) {
			$scope.email = $scope.userSign.email;
			$scope.password = $scope.userSign.password;
		}

		$scope.emailBool = function(bool){
			$scope.emailBlur = bool;
		}
		$scope.passwordBool = function(bool){
			$scope.passwordBlur = bool;
		}
	    $scope.reset = function() {

	    	$scope.setPassword = $scope.password;
	    	if (!$scope.savePassword) {
	    		console.log(10);
	    		$scope.setPassword = null;
	    	}
    		var userSign = {
    			email : $scope.email,
    			password : $scope.setPassword
    		}
	    	// 设置一个session;
	       	localStorage.setItem('userSign',JSON.stringify(userSign));
	       	window.location = "http://localhost/child_watch/#/";
	    };
	    // $scope.reset();

	});
</script>
<script src="../js/public.js"></script>
</body>
</html>